import { BasicColumn, FormSchema } from '@/components/Table';
import { formatToDateTime, formatToDate } from '@/utils/dateUtil';

export const columns: BasicColumn[] = [
  {
    title: '企业',
    dataIndex: ['connection', 'partner', 'name'],
    width: 150,
  },
  {
    title: '日期',
    dataIndex: 'date',
    width: 80,
  },
  {
    title: '执行状态',
    dataIndex: 'success',
    width: 80,
    customRender: ({ record }) => {
      return !!record.success? '成功': '失败';
    },
  },
  {
    title: '内容',
    dataIndex: 'content',
    width: 200,
  },
  {
    title: '开始时间',
    dataIndex: 'start_at',
    width: 120,
    customRender: ({ record }) => {
      return formatToDateTime(record.start_at);
    },
  },
  {
    title: '结束时间',
    dataIndex: 'end_at',
    width: 120,
    customRender: ({ record }) => {
      return formatToDateTime(record.end_at);
    },
  },
  {
    title: '用时(秒)',
    dataIndex: 'time_spent',
    width: 80,
    customRender: ({ record }) => {
      return record.time_spent / 1000;
    },
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '名称',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    field: 'date',
    label: '日期',
    component: 'DatePicker',
    defaultValue: formatToDate(),
    colProps: { span: 6 },
    componentProps: {
      valueFormat: 'YYYY-MM-DD',
    }
  },
  {
    field: 'success',
    label: '执行状态',
    component: 'Select',
    componentProps: {
      options: [
        {
          label: '成功',
          value: true,
        },
        {
          label: '失败',
          value: false,
        },
      ],
    },
    colProps: { span: 6 },
  },
];
